const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin")

module.exports = {
    mode: "production",
    entry: path.resolve(process.cwd(), "./src/index.js"),
    output: {
        path: path.resolve(process.cwd(), "./dist"),
        filename: "[name].js",
        publicPath:"/"
    },
    resolve: {
        alias: {  // 别名
            "@": path.resolve(process.cwd(), "src") // @ 符号直接指向 src 路径地址 ；
        }
    },
    module: {
        rules: [{
            test: /\.html$/i,
            loader: "html-loader",
        },
        {
            test: /\.ejs$/,
            loader: 'ejs-loader',
            options: {
                variable: 'data', // 传入到模板里的数据名称 
            }
        },{
            test: /\.css$/i,
            use: [
                "style-loader",
                'css-loader'
            ]
        }],
    },
    plugins: [
        new HtmlWebpackPlugin({
            title: "myapp",
            filename: "index.html",  // 打包之后的html名称
            template: "./src/public/index.html" // 打包之前的index.html文件的路径
        }),
        new CopyWebpackPlugin({
            patterns: [{
                from: "src/public",  // 打包之前的目录地址 
                to: "public",  // 打包之后的目录地址；
                globOptions: {
                    ignore: ["**/index.html"] // 排除index.html
                }
            },{
                from:"src/static",
                to:"./"
            }],
        })
    ]
}